Skip to content

Instantly share code, notes, and snippets.

@mandrasch
Last active April 7, 2022 14:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mandrasch/228f8fb8f3738fe4c7b8e2295af578aa to your computer and use it in GitHub Desktop.
Save mandrasch/228f8fb8f3738fe4c7b8e2295af578aa to your computer and use it in GitHub Desktop.
.htaccess - fix http to https redirect for DDEV
# Debug trick, uncomment to check values:
# ErrorDocument 404 "Request: %{THE_REQUEST} Referrer: %{HTTP_REFERER}, Host: %{HTTP_HOST}, HTTPS: %{HTTPS}, HTTP:X-Forwarded-Proto: %{HTTP:X-Forwarded-Proto}"
# RewriteRule ^ - [L,R=404]
# The general rule for redirecting HTTP to HTTPS:
# --> Results in "Error too many redirects" in DDEV, because %{HTTPS} is always == off
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</IfModule>
# Fixed version, check also that HTTP:X-Forward-Proto is off (= http), redirect
# found this via .ddev/apache/apache-site.conf -> https://gist.github.com/nurtext/b6ac07ac7d8c372bc8eb
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP:X-Forwarded-Proto} !https [NC]
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</IFModule>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment